var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/defineProperty")), e = require("../../services/api.js");

function a(t, e) {
    var a = Object.keys(t);
    if (Object.getOwnPropertySymbols) {
        var n = Object.getOwnPropertySymbols(t);
        e && (n = n.filter(function(e) {
            return Object.getOwnPropertyDescriptor(t, e).enumerable;
        })), a.push.apply(a, n);
    }
    return a;
}

Page({
    data: {
        text: 1,
        lists: [],
        active: 0,
        disabled: !0
    },
    onLoad: function(t) {
        var a = this;
        (0, e.getVipLists)().then(function(t) {
            if (200 === t.data.code) {
                var e = t.data.data.map(function(t) {
                    return t.sheet = t.title + " " + t.price + "元", t;
                });
                a.setData({
                    lists: e,
                    disabled: !1
                });
            }
        });
    },
    chooseVip: function() {
        var t = this;
        if (this.data.disabled) wx.showModal({
            title: "提示",
            content: "未知错误，请稍后再试",
            showCancel: !1
        }); else {
            var e = this.data.lists.map(function(t) {
                return t.sheet;
            });
            wx.showActionSheet({
                itemList: e,
                success: function(e) {
                    t.setData({
                        active: e.tapIndex
                    });
                }
            });
        }
    },
    payVip: function() {
        this.data.disabled ? wx.showModal({
            title: "提示",
            content: "未知错误，请稍后再试",
            showCancel: !1
        }) : (wx.showLoading({
            title: "正在创建订单",
            mask: !0
        }), (0, e.getVipOrder)({
            rule_id: this.data.lists[this.data.active].id
        }).then(function(n) {
            200 === n.data.code ? (0, e.createGoodsPay)({
                pay_type: 1,
                trade_type: "mini_program",
                order_group: "vip",
                data: {
                    order_sn: n.data.data.o_id
                }
            }).then(function(e) {
                200 === e.data.code && wx.requestPayment(Object.assign({}, function(e) {
                    for (var n = 1; n < arguments.length; n++) {
                        var o = null != arguments[n] ? arguments[n] : {};
                        n % 2 ? a(o, !0).forEach(function(a) {
                            (0, t.default)(e, a, o[a]);
                        }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(o)) : a(o).forEach(function(t) {
                            Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(o, t));
                        });
                    }
                    return e;
                }({}, e.data.data.config), {
                    timeStamp: e.data.data.config.timeStamp || e.data.data.config.timestamp,
                    success: function() {
                        wx.hideLoading(), wx.showToast({
                            title: "支付成功",
                            mask: !0
                        }), setTimeout(function() {});
                    },
                    fail: function(t) {
                        console.log(t), wx.showModal({
                            title: "提示",
                            content: "支付失败",
                            showCancel: !1
                        });
                    }
                }));
            }) : wx.showModal({
                title: "提示",
                content: n.data.message,
                showCancel: !1
            });
        }));
    },
    onReady: function() {},
    copywx: function() {
        wx.setClipboardData({
            data: "19983077261",
            success: function(t) {
                wx.showModal({
                    title: "提示",
                    content: "已复制客服微信",
                    showCancel: !1
                });
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});